﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using WPFDBBrowser.Interfaces.DBTreeView;

namespace WPFDBBrowser.Interfaces
{
    /// <summary>
    /// Needs to be implemented by DBFactory classes fro WPFDBBrowser.
    /// </summary>
    public interface IDBFactory : IName
    {

        string FriendlyName
        {
            get;
        }
        /// <summary>
        /// Gets the connection string builder.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>Implementation of DbConnectionStringBuilder.</returns>
        DbConnectionStringBuilder GetConnectionStringBuilder(string connectionString);
        /// <summary>
        /// Checks the connection.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>Return true, if connection string is correct and connection to DB server was successful; else false.</returns>
        bool CheckConnection(string connectionString);

        /// <summary>
        /// Gets the table names.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>List of table names.</returns>
        System.Collections.Generic.IEnumerable<ITable> GetTables(string connectionString);
        /// <summary>
        /// Gets the view names.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>List of view names.</returns>
        IEnumerable<IView> GetViews(string connectionString);
        /// <summary>
        /// Gets the columns.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <returns>Columns for selected table.</returns>
        IEnumerable<IColumn> GetColumns(string connectionString, string tableName);
        /// <summary>
        /// Gets the query.
        /// </summary>
        /// <param name="tableOrView">The table or view.</param>
        /// <param name="numberOfRows">The number of rows which will be returned from DB.</param>
        /// <returns>
        /// Query generated from table or view definition.
        /// </returns>
        string GetQuery(IColumnContainer tableOrView, int numberOfRows);
        /// <summary>
        /// Prepares the view query.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="query">The number of rows which will be returned from DB.</param>
        /// <returns>
        /// DataTable filled with data returned from DB.
        /// </returns>
        DataTable RunQuery(string connectionString, string query);
        /// <summary>
        /// Prepares the view query for run.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="numberOfRows">The number of rows which will be returned from DB.</param>
        /// <returns>Modified query.</returns>
        string PrepareViewQuery(IView view, int numberOfRows);
    }

    /// <summary>
    /// Allow naming of implemented classes.
    /// There are Name, Friendly name and Description properties.
    /// </summary>
    public interface IName
    {
        /// <summary>
        /// Gets the name of the instance.
        /// </summary>
        /// <value>The name.</value>
        string Name { get; }

        string Type
        {
            get;
        }

        string Description
        {
            get;
        }
    }
}
